package com.mengyu.moeisland.utils

import android.app.Activity
import android.content.Context
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment

fun View.showToast(msg:String){
    showToast(context,msg)
}
fun Activity.showToast(msg:String){
    showToast(this,msg)
}
fun Fragment.showToast(msg:String){
    context?.let { showToast(it,msg) }
}
fun showToast(context:Context,msg: String){
    Toast.makeText(context,msg,Toast.LENGTH_LONG).show()
}


var lastClickTime: Long = 0

var DIFF: Long = 1000

var lastButtonId = -1

fun View.onClick(onclic:(View)->Unit){
    setOnClickListener {
        val time = System.currentTimeMillis()
        val timeD = time - lastClickTime
        if (lastClickTime > 0 && timeD < DIFF) {
            LGG.e("isFastDoubleClick", "短时间内按钮多次触发")
        }else{
            onclic.invoke(it)
            lastClickTime = time
        }
    }
}